package cn.yh.springbootjwt.service.impl;

import cn.yh.springbootjwt.domain.entity.UserDo;
import cn.yh.springbootjwt.domain.query.UserQuery;
import cn.yh.springbootjwt.domain.query.UserUpdate;
import cn.yh.springbootjwt.domain.vo.UserVo;
import cn.yh.springbootjwt.mapper.UserMapper;
import cn.yh.springbootjwt.service.IUserService;
import cn.yh.springbootjwt.utils.JWTUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserMapper userMapper;


    @Override
    public UserDo loginByUsername(String username) {
        return userMapper.selectByUsername(username);
    }

    @Override
    public UserVo getUserInfo() {
        Long userId = JWTUtils.getUserIdByClaim();
        return userMapper.selectByUserId(userId);
    }

    @Override
    public int createUser(UserQuery userQuery) {
        if (userQuery == null || userQuery.getUsername() == null || userQuery.getPassword() == null){
            return 0;
        }
        return userMapper.createUser(userQuery.getUsername(), userQuery.getPassword());
    }

    @Override
    public int updateUser(UserUpdate userUpdate) {
        return userMapper.updateUser(userUpdate.getUsername(), userUpdate.getPassword(), JWTUtils.getUserIdByClaim());
    }

    @Override
    public int deleteUser() {

        return userMapper.deleteUserByUserId(JWTUtils.getUserIdByClaim());
    }
    //新增 讲解实现 CRUD标签



}
